﻿using JustMetClientTest.Tools;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace JustMetClientTest
{
    public partial class TestForm : Form
    {
        public long AppRam = 0;
        public static TestForm _TestForm = null;

        public TestForm()
        {
            InitializeComponent();
            _TestForm = this;
            //DownLoadTest();

        }

        //1.FTP测试
        private void DownLoadTest()
        {
            FtpHelper ftpHelper = new FtpHelper("58.87.76.162", @"/JustMetClient/Update/JustMetClient", "noah","noah,123");
            ftpHelper.Download("D://CoCo//", "1.0.0.2.version");
        }

        //2.内存：专用工作集 和 共享工作集 ，此处为专用工作集
        public static long PerformanceCounter()
        {
            long value = 0;
            Process p = null;
            try
            {
                p = Process.GetCurrentProcess();
                var ps = Process.GetCurrentProcess();
                PerformanceCounter pf1 = new PerformanceCounter("Process", "Working Set - Private", p.ProcessName);
                value = (long)(pf1.NextValue() / 1024);
                Console.WriteLine("PerformanceCounter--", value.ToString());
                _TestForm.TBLog.AppendText("PerformanceCounter--:" + value.ToString()+"\n");
            }
            catch (Exception e)
            {
                Console.WriteLine("PerformanceCounter--", e.ToString());
                _TestForm.TBLog.AppendText("PerformanceCounter--:" + e.ToString() + "\n");
            }
            finally { p?.Dispose(); }
            return value;
        }

        private void Timer1S_Tick(object sender, EventArgs e)
        {
            AppRam = PerformanceCounter() / 1024;
            LBRamInfo.Text = $"程序占用RAM：{AppRam} MB"; 
        }

        private void TestForm_Load(object sender, EventArgs e)
        {

        }
    }
}
